cmake_minimum_required(VERSION 2.8.11)

set(TARGET_NAME TTKCore)
project(${TARGET_NAME})

if(COMMAND cmake_policy)
    cmake_policy(SET CMP0003 OLD)
    cmake_policy(SET CMP0005 OLD)
endif(COMMAND cmake_policy)

add_definitions(-DQT_NO_DEBUG)
add_definitions(-DQT_THREAD)

add_subdirectory(musicCoreKits)
add_subdirectory(musicLrcKits)
add_subdirectory(musicNetworkKits)
add_subdirectory(musicRemoteKits)
add_subdirectory(musicSearchKits)
add_subdirectory(musicToolsKits)
add_subdirectory(musicToolsSetsKits)
add_subdirectory(musicUiKits)
add_subdirectory(musicUserKits)
add_subdirectory(musicVideokits)
add_subdirectory(musicWidgetCoreKits)
add_subdirectory(musicWidgetKits)

get_property(MUSIC_CORE_KITS_HEADERS GLOBAL PROPERTY "MUSIC_CORE_KITS_HEADERS")
get_property(MUSIC_LRC_KITS_HEADERS GLOBAL PROPERTY "MUSIC_LRC_KITS_HEADERS")
get_property(MUSIC_NETWORK_KITS_HEADERS GLOBAL PROPERTY "MUSIC_NETWORK_KITS_HEADERS")
get_property(MUSIC_REMOTE_KITS_HEADERS GLOBAL PROPERTY "MUSIC_REMOTE_KITS_HEADERS")
get_property(MUSIC_SEARCH_KITS_HEADERS GLOBAL PROPERTY "MUSIC_SEARCH_KITS_HEADERS")
get_property(MUSIC_TOOLS_KITS_HEADERS GLOBAL PROPERTY "MUSIC_TOOLS_KITS_HEADERS")
get_property(MUSIC_TOOLSETS_KITS_HEADERS GLOBAL PROPERTY "MUSIC_TOOLSETS_KITS_HEADERS")
get_property(MUSIC_UI_KITS_HEADERS GLOBAL PROPERTY "MUSIC_UI_KITS_HEADERS")
get_property(MUSIC_USER_KITS_HEADERS GLOBAL PROPERTY "MUSIC_USER_KITS_HEADERS")
get_property(MUSIC_VIDEO_KITS_HEADERS GLOBAL PROPERTY "MUSIC_VIDEO_KITS_HEADERS")
get_property(MUSIC_WIDGETCORE_KITS_HEADERS GLOBAL PROPERTY "MUSIC_WIDGETCORE_KITS_HEADERS")
get_property(MUSIC_WIDGET_KITS_HEADERS GLOBAL PROPERTY "MUSIC_WIDGET_KITS_HEADERS")

set(MUSIC_HEADERS
    ${MUSIC_CORE_KITS_HEADERS}
    ${MUSIC_LRC_KITS_HEADERS}
    ${MUSIC_NETWORK_KITS_HEADERS}
    ${MUSIC_REMOTE_KITS_HEADERS}
    ${MUSIC_SEARCH_KITS_HEADERS}
    ${MUSIC_TOOLS_KITS_HEADERS}
    ${MUSIC_TOOLSETS_KITS_HEADERS}
    ${MUSIC_UI_KITS_HEADERS}
    ${MUSIC_USER_KITS_HEADERS}
    ${MUSIC_VIDEO_KITS_HEADERS}
    ${MUSIC_WIDGETCORE_KITS_HEADERS}
    ${MUSIC_WIDGET_KITS_HEADERS}
    ${MUSIC_LIB_DIR}/musicapplication.h
    ${MUSIC_LIB_DIR}/musicleftareawidget.h
    ${MUSIC_LIB_DIR}/musictopareawidget.h
    ${MUSIC_LIB_DIR}/musicrightareawidget.h
    ${MUSIC_LIB_DIR}/musicbottomareawidget.h
    ${MUSIC_LIB_DIR}/musicapplicationobject.h
  )

get_property(MUSIC_CORE_KITS_SOURCES GLOBAL PROPERTY "MUSIC_CORE_KITS_SOURCES")
get_property(MUSIC_LRC_KITS_SOURCES GLOBAL PROPERTY "MUSIC_LRC_KITS_SOURCES")
get_property(MUSIC_NETWORK_KITS_SOURCES GLOBAL PROPERTY "MUSIC_NETWORK_KITS_SOURCES")
get_property(MUSIC_REMOTE_KITS_SOURCES GLOBAL PROPERTY "MUSIC_REMOTE_KITS_SOURCES")
get_property(MUSIC_SEARCH_KITS_SOURCES GLOBAL PROPERTY "MUSIC_SEARCH_KITS_SOURCES")
get_property(MUSIC_TOOLS_KITS_SOURCES GLOBAL PROPERTY "MUSIC_TOOLS_KITS_SOURCES")
get_property(MUSIC_TOOLSETS_KITS_SOURCES GLOBAL PROPERTY "MUSIC_TOOLSETS_KITS_SOURCES")
get_property(MUSIC_USER_KITS_SOURCES GLOBAL PROPERTY "MUSIC_USER_KITS_SOURCES")
get_property(MUSIC_VIDEO_KITS_SOURCES GLOBAL PROPERTY "MUSIC_VIDEO_KITS_SOURCES")
get_property(MUSIC_WIDGETCORE_KITS_SOURCES GLOBAL PROPERTY "MUSIC_WIDGETCORE_KITS_SOURCES")
get_property(MUSIC_WIDGET_KITS_SOURCES GLOBAL PROPERTY "MUSIC_WIDGET_KITS_SOURCES")

set(MUSIC_SOURCES
    ${MUSIC_CORE_KITS_SOURCES}
    ${MUSIC_LRC_KITS_SOURCES}
    ${MUSIC_NETWORK_KITS_SOURCES}
    ${MUSIC_REMOTE_KITS_SOURCES}
    ${MUSIC_SEARCH_KITS_SOURCES}
    ${MUSIC_TOOLS_KITS_SOURCES}
    ${MUSIC_TOOLSETS_KITS_SOURCES}
    ${MUSIC_USER_KITS_SOURCES}
    ${MUSIC_VIDEO_KITS_SOURCES}
    ${MUSIC_WIDGETCORE_KITS_SOURCES}
    ${MUSIC_WIDGET_KITS_SOURCES}
    ${MUSIC_LIB_DIR}/musicapplication.cpp
    ${MUSIC_LIB_DIR}/musicleftareawidget.cpp
    ${MUSIC_LIB_DIR}/musictopareawidget.cpp
    ${MUSIC_LIB_DIR}/musicrightareawidget.cpp
    ${MUSIC_LIB_DIR}/musicbottomareawidget.cpp
    ${MUSIC_LIB_DIR}/musicapplicationobject.cpp
  )

get_property(MUSIC_UIS GLOBAL PROPERTY "MUSIC_UIS")

if(WIN32)
    list(APPEND MUSIC_SOURCES ${TARGET_NAME}.rc)
endif()

if(TTK_QT_VERSION VERSION_GREATER "4")
  QT5_WRAP_UI(MUSIC_UIS_H ${MUSIC_UIS})
  QT5_WRAP_CPP(MUSIC_MOC_H ${MUSIC_HEADERS})
  
  if(TTK_BUILD_SHARED)
    add_library(${TARGET_NAME} SHARED ${MUSIC_SOURCES} ${MUSIC_UIS_H} ${MUSIC_MOC_H} ${MUSIC_HEADERS})
  else()
    add_library(${TARGET_NAME} STATIC ${MUSIC_SOURCES} ${MUSIC_UIS_H} ${MUSIC_MOC_H} ${MUSIC_HEADERS})
  endif()
  list(APPEND QT5_LIBS Qt5::Core Qt5::Network Qt5::Sql Qt5::Xml Qt5::Gui Qt5::Widgets Qt5::Multimedia Qt5::MultimediaWidgets Qt5::WinExtras ${QMMP_LIBRARY} TTKUi TTKExtras TTKWatcher zlib -lIphlpapi -luser32)
  if(UNIX)
    list(REMOVE_ITEM QT5_LIBS Qt5::WinExtras -lIphlpapi -luser32)
  endif()
  target_link_libraries(${TARGET_NAME} ${QT5_LIBS})
else()
  QT4_WRAP_UI(MUSIC_UIS_H ${MUSIC_UIS})
  QT4_WRAP_CPP(MUSIC_MOC_H ${MUSIC_HEADERS})

  if(TTK_BUILD_SHARED)
    add_library(${TARGET_NAME} SHARED ${MUSIC_SOURCES} ${MUSIC_UIS_H} ${MUSIC_MOC_H} ${MUSIC_HEADERS})
  else()
    add_library(${TARGET_NAME} STATIC ${MUSIC_SOURCES} ${MUSIC_UIS_H} ${MUSIC_MOC_H} ${MUSIC_HEADERS})
  endif()
  list(APPEND QT4_LIBS ${QMMP_LIBRARY} ${QT_QTMULTIMEDIA_LIBRARY} ${QT_QTSQL_LIBRARY} ${QT_QTXML_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTNETWORK_LIBRARY} ${QT_QTCORE_LIBRARY} TTKUi TTKExtras TTKWatcher zlib -lIphlpapi -luser32)
  if(UNIX)
    list(REMOVE_ITEM QT4_LIBS ${QT_QTMULTIMEDIA_LIBRARY} -lIphlpapi -luser32)
    list(APPEND QT4_LIBS -lQtMultimediaKit)
  endif()
  target_link_libraries(${TARGET_NAME} ${QT4_LIBS})
endif()
